import logging


def setup_logger():
    # 设置日志级别
    logging.basicConfig(level=logging.INFO)

    # 创建Logger对象
    logger = logging.getLogger(__name__)

    # 创建FileHandler对象，指定日志文件路径和模式
    file_handler = logging.FileHandler('logfile.log')

    # 创建Formatter对象，指定日志消息的格式
    formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(filename)s:%(lineno)d - %(message)s')

    # 将Formatter对象添加到FileHandler
    file_handler.setFormatter(formatter)

    # 将FileHandler添加到Logger对象
    logger.addHandler(file_handler)
    stream_handler = logging.StreamHandler()
    stream_handler.setFormatter(formatter)
    logger.addHandler(stream_handler)
    return logger


# 在模块加载时配置Logger
logger = setup_logger()
